#coding = utf8

import os
import io
import sys

_bmfont_file = "bmfont_4.fnt"
_decrease_amount = 1

with io.open(_bmfont_file, "r", encoding="utf-8") as file_obj:
    file_data = ""
    
    for line in file_obj:
        if "xadvance=" in line:
            xadvance_index = line.index("xadvance=")
            xadvance_old_value = line[xadvance_index+9:xadvance_index+11]
            xadvance_old_value = int(xadvance_old_value)
            xadvance_new_value = xadvance_old_value - _decrease_amount
            
            xadvance_old_string = "xadvance=" + str(xadvance_old_value)
            xadvance_new_string = "xadvance=" + str(xadvance_new_value)
            
            print("xadvance_old_string = " + xadvance_old_string + ", xadvance_new_string = " + xadvance_new_string)
            line = line.replace(xadvance_old_string, xadvance_new_string)
            
        if "width=" in line:
            width_index = line.index("width=")
            width_old_value = line[width_index+6:width_index+8]
            width_old_value = int(width_old_value)
            width_new_value = width_old_value - _decrease_amount
            
            width_old_string = "width=" + str(width_old_value)
            width_new_string = "width=" + str(width_new_value)
            
            print("width_old_string = " + width_old_string + ", width_new_string = " + width_new_string)
            line = line.replace(width_old_string, width_new_string)
        
        file_data += line
            
with io.open(_bmfont_file, "w", encoding="utf-8") as file_obj:
    file_obj.write(file_data)

os.system("pause")